package com.dw.etl.core.service;

import com.dw.etl.common.util.UUIDUtil;
import  com.dw.etl.common.vo.PaginationVO;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import com.dw.etl.core.api.BaseIndexConfTbService;
import com.dw.etl.core.mapper.BaseIndexConfTbMapper;
import com.dw.etl.core.bean.model.BaseIndexConfTb;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;

/**
 * baseIndexConfTb服务实现类
 * Created by hozeData on 2021/06/21.
 */
@Service
@Transactional
public class BaseIndexConfTbServiceImpl implements BaseIndexConfTbService{

    private static final Logger LOGGER = LoggerFactory.getLogger(BaseIndexConfTbServiceImpl.class);

    @Autowired
    private BaseIndexConfTbMapper baseIndexConfTbMapper;

    @Override
    public int insert(BaseIndexConfTb baseIndexConfTb) {
        if(StringUtils.isEmpty(baseIndexConfTb.getPk())){
            String uuid32 = UUIDUtil.getUUID32();
            baseIndexConfTb.setPk(uuid32);
        }
        return baseIndexConfTbMapper.insert(baseIndexConfTb);
    }

    @Override
    public int insertSelective(BaseIndexConfTb baseIndexConfTb)  {
        if(StringUtils.isEmpty(baseIndexConfTb.getPk())){
            String uuid32 = UUIDUtil.getUUID32();
            baseIndexConfTb.setPk(uuid32);
        }
        return baseIndexConfTbMapper.insertSelective(baseIndexConfTb);
    }

    @Override
    public int deleteById(String pk)  {
        return baseIndexConfTbMapper.deleteByPrimaryKey(pk);
    }

    @Override
    public int updateByIdSelective(BaseIndexConfTb baseIndexConfTb)  {

        return baseIndexConfTbMapper.updateByPrimaryKeySelective(baseIndexConfTb);
    }

    @Override
    public int updateById(BaseIndexConfTb baseIndexConfTb)  {
        return baseIndexConfTbMapper.updateByPrimaryKey(baseIndexConfTb);
    }

    @Override
    public BaseIndexConfTb getById(String pk)  {
        return baseIndexConfTbMapper.selectByPrimaryKey(pk);
    }

    @Override
    public List<BaseIndexConfTb> findByModel(BaseIndexConfTb baseIndexConfTb)  {
        return baseIndexConfTbMapper.findByModel(baseIndexConfTb);
    }

    @Override
    public PaginationVO<BaseIndexConfTb> findPageByModel(BaseIndexConfTb baseIndexConfTb, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum == null? 1 : pageNum, pageSize == null? 10 : pageSize);
        List<BaseIndexConfTb> quesList = baseIndexConfTbMapper.findByModel(baseIndexConfTb);
        PageInfo<BaseIndexConfTb> pageInfo = new PageInfo<>(quesList);
        PaginationVO<BaseIndexConfTb> paginationVo = new PaginationVO(pageInfo.getTotal(), pageInfo.getList());
        return paginationVo;
    }





}
